package com.zhangxiaofanfan.hotcode.first;

import java.util.PriorityQueue;
import java.util.Stack;

/**
 *
 *
 * @date 2024-06-29 03:21:25
 * @author zhangxiaofanfan
 */
public class HotCode070 {
    public static void main(String[] args) {
        MinStack stack = new MinStack();
        stack.push(-2);
        stack.push(0);
        stack.push(-3);
        System.out.println(stack.getMin());
        stack.pop();
        System.out.println(stack.top());
        System.out.println(stack.getMin());
    }
}

class MinStack {

    private final Stack<Integer> stack;
    private final PriorityQueue<Integer> priorityQueue;

    public MinStack() {
        stack = new Stack<>();
        priorityQueue = new PriorityQueue<>();
    }

    public void push(int val) {
        priorityQueue.add(val);
        stack.push(val);
    }

    public void pop() {
        Integer pop = stack.pop();
        priorityQueue.remove(pop);
    }

    public int top() {
        return stack.getLast();
    }

    public int getMin() {
        return priorityQueue.element();
    }
}
